const http = require('http');
const fs = require('fs');

const server = http.createServer((request, response) => {
  // response.setHeader('content-type', 'text/html;charset=utf-8');

  // 获取请求url的路径
  let { pathname } = new URL(request.url, 'http://127.0.0.1');
  // 获取文件对应路径
  let html = fs.readFileSync(__dirname + '/index.html');
  console.log(pathname)
  if (pathname !== '/') {
    html = fs.readFileSync(__dirname + pathname);
  }
  // response.statuCode = 404;
  // response.end(`404 Not Found`);

  // end 支持输出buffer
  response.end(`${html}`);
})

server.listen(9000, () => {
  console.log('服务已启动...,访问地址：http://127.0.0.0:9000')
})

function changeColo(item) {
  console.log(item)
}